package com.zp.mvppractice.mvp1;

import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;

import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by izp on 2017/7/8.
 */

public abstract class BaseActivity <V,P extends BasePresenter<V>> extends RxAppCompatActivity implements BaseView{
    protected P mPresenter;
    private Unbinder unbinder;
    public abstract P initPresenter();
    public abstract @LayoutRes int setContentLayout();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setContentLayout());
        mPresenter = initPresenter();
//        mPresenter = bindPresenter();
        unbinder = ButterKnife.bind(this);

    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.attach((V) this);
    }

    @Override
    protected void onDestroy() {
        mPresenter.detach();
        if (null!=unbinder){
            unbinder.unbind();
        }
        super.onDestroy();
    }
}
